package com.itcast.ixun.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.itcast.ixun.R;
import com.itcast.ixun.adapter.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/24.
 */
public class HomeFragment extends Fragment {

    private List<String> tabNames;
    private ViewPagerAdapter viewPagerAdapter;
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private List<Fragment> fragmentList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout_home);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager_home);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        tabNames = new ArrayList<>();
        fragmentList = new ArrayList<>();
        tabNames.add("热门");
        tabNames.add("娱乐");
        tabNames.add("美食");
        tabNames.add("创意");
        tabNames.add("情感");
        tabNames.add("美女");
        tabNames.add("体育");
        tabNames.add("健康");
        tabNames.add("互动");
        tabNames.add("萌宠");
        tabNames.add("奇趣");
        tabNames.add("爆笑");
        tabNames.add("视频");
        tabNames.add("生活");
        tabNames.add("资讯");
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
        fragmentList.add(new HomeHotFragment());
     
        viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager(), tabNames, fragmentList);
        viewPager.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);

    }

}
